package com.chenju.javastatic.utils;

import java.util.*;

public class EasyListUtils {
    public static <T> List<T> asArrayList(T[] array) {
        if (array == null) {
            return new ArrayList<>();
        }
        ArrayList<T> list = new ArrayList<>(array.length);
        list.addAll(Arrays.asList(array));

        return list;
    }

    public static List<Byte> asArrayList(byte[] byteArray) {
        if (byteArray == null) {
            return new ArrayList<>();
        } else {
            ArrayList<Byte> byteList = new ArrayList<>(byteArray.length);
            byte[] var2 = byteArray;
            int var3 = byteArray.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                byte b = var2[var4];
                byteList.add(b);
            }

            return byteList;
        }
    }
    public static List<Boolean> asArrayList(boolean[] booleanArray) {
        if (booleanArray == null) {
            return new ArrayList<>();
        } else {
            ArrayList<Boolean> booleanList = new ArrayList<>(booleanArray.length);
            boolean[] var2 = booleanArray;
            int var3 = booleanArray.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                boolean b = var2[var4];
                booleanList.add(b);
            }

            return booleanList;
        }
    }

    public static List<Short> asArrayList(short[] shortArray) {
        if (shortArray == null) {
            return new ArrayList<>();
        } else {
            ArrayList<Short> shortList = new ArrayList<>(shortArray.length);
            short[] var2 = shortArray;
            int var3 = shortArray.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                short s = var2[var4];
                shortList.add(s);
            }

            return shortList;
        }
    }

    public static List<Character> asArrayList(char[] charArray) {
        if (charArray == null) {
            return new ArrayList<>();
        } else {
            ArrayList<Character> charList = new ArrayList<>(charArray.length);
            char[] var2 = charArray;
            int var3 = charArray.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                char c = var2[var4];
                charList.add(c);
            }

            return charList;
        }
    }

    public static List<Integer> asArrayList(int[] intArray) {
        if (intArray == null) {
            return new ArrayList<>();
        } else {
            ArrayList<Integer> intList = new ArrayList<>(intArray.length);
            int[] var2 = intArray;
            int var3 = intArray.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                int i = var2[var4];
                intList.add(i);
            }

            return intList;
        }
    }

    public static List<Float> asArrayList(float[] floatArray) {
        if (floatArray == null) {
            return new ArrayList<>();
        } else {
            ArrayList<Float> floatList = new ArrayList<>(floatArray.length);
            float[] var2 = floatArray;
            int var3 = floatArray.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                float f = var2[var4];
                floatList.add(f);
            }

            return floatList;
        }
    }

    public static List<Long> asArrayList(long[] longArray) {
        if (longArray == null) {
            return new ArrayList<>();
        } else {
            ArrayList<Long> longList = new ArrayList<>(longArray.length);
            long[] var2 = longArray;
            int var3 = longArray.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                long l = var2[var4];
                longList.add(l);
            }

            return longList;
        }
    }

    public static List<Double> asArrayList(double[] doubleArray) {
        if (doubleArray == null) {
            return new ArrayList<>();
        } else {
            ArrayList<Double> doubleList = new ArrayList<>(doubleArray.length);
            double[] var2 = doubleArray;
            int var3 = doubleArray.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                double d = var2[var4];
                doubleList.add(d);
            }

            return doubleList;
        }
    }

    public static <T> List<T> asArrayList(T t){
        List<T> list = new ArrayList<>();
        list.add(t);
        return list;
    }

    public static <T> List<T> add(List<T> list, T element) {
        List<T> newList = list == null ? new ArrayList<>(1) : list;
        newList.add(element);
        return newList;
    }

    public static String asString(List<String> list, String sep) {
        if (list.size() > 0) {
            return String.join(sep, list);
        }
        return "";
    }

    public static Map<String, Object> toMap(List<Object> list) {
        if (list == null) {
            return null;
        }
//        if (list.size() % 2 != 0) {
//            throw new IllegalArgumentException("list必须包含偶数个元素！");
//        }

        Map<String, Object> map = new HashMap<>();
        for (int i = 0; i < list.size(); i += 2) {
            String key = (String) list.get(i);
            Object value = list.get(i + 1);
            map.put(key, value);
        }
        return map;
    }
}
